/*
 * Copyright (c) 2012 Thomson Reuters. All rights reserved.
 *
 * This software is confidential and all proprietary rights in and to the
 * software are owned by Thomson Reuters. All use of the software is subject to
 * and governed by the terms and conditions of the applicable license agreement
 * entered into with Thomson Reuters by the licensee (the "License Agreement").
 * Except for the rights expressly granted under the License Agreement, no
 * other rights to use or disclose this software are granted or permitted.
*/
package axil.stdlib.core.operator;

import axil.api.AxilObject;
import axil.api.extend.Operator;
import axil.stdlib.core.type.Nil;

import static axil.framework.Functions.bool;


/**
 * Compare two objects for equivalence but not strict equality.
 */
public class Equivalent implements Operator {
	/**
	 * Execute this operator with the given operands. The given operands have
	 * already been evaluated. If this operation does not make sense for the
	 * given operands, then an exception is thrown.
	 *
	 * @param left
	 * 	The left operand, which can be any Axil object. The value given is
	 * 	never null but may be the nil object (Axil.NIL).
	 *
	 * @param right
	 * 	The left operand, which can be any Axil object. The value given is
	 * 	never null but may be the nil object (Axil.NIL).
	 *
	 * @return
	 * 	Returns any Axil object, but not null.
	 */
	public AxilObject eval(AxilObject left, AxilObject right) {
		if ((left == Nil.object) || (right == Nil.object)) {
			return bool(left == right);
		}
		return bool(left.equivalentTo(right));
	}
}
